package com.biu.billiards.controller;


import com.biu.billiards.model.vo.device.AddDeviceVo;
import com.biu.billiards.model.vo.device.GetDeviceVo;
import com.biu.billiards.model.vo.device.UpdateDeviceVO;
import com.biu.billiards.model.vo.mqtt.OpenDeviceVo;
import com.biu.billiards.response.BaseResponse;
import com.biu.billiards.response.RespGenerator;
import com.biu.billiards.service.IDeviceService;
import com.biu.billiards.task.AsyncTask;
import com.biu.billiards.utils.RedisUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xue
 * @since 2023-10-25
 */
@RestController
@RequestMapping()
public class DeviceController {

    @Resource
    private IDeviceService deviceService;


    @Resource
    private AsyncTask asyncTask;



//    @ApiOperation(value = "www")
//    @PostMapping("/cs")
//    public void cs(@RequestBody Integer open) {
//
//        deviceService.openFan(open);
//   //  deviceService.openVrv(open);
//
//    }


    @ApiOperation(value = "门禁")
    @PostMapping("/openDoor")
    public BaseResponse<Boolean> openDoor(@RequestBody OpenDeviceVo openDeviceVo) throws InterruptedException {
        return RespGenerator.returnOK(asyncTask.openDoor(openDeviceVo));


    }
    @ApiOperation(value = "获取设备数据")
    @PostMapping("/getDevicePage")
    public BaseResponse<Map<String,Object>> getDevicePage(@RequestBody GetDeviceVo getDeviceVo) {
        return RespGenerator.returnOK(deviceService.getDevicePage(getDeviceVo));
    }


    @ApiOperation(value = "修改设备信息")
    @PutMapping("/updateDevice")
    public BaseResponse<Boolean> updateDevice(@RequestBody UpdateDeviceVO updateDeviceVO) {
        return RespGenerator.returnOK(deviceService.updateDevice(updateDeviceVO));
    }


    @ApiOperation(value = "新增设备信息")
    @PostMapping("/addDevice")
    public BaseResponse<Boolean> addDevice(@RequestBody AddDeviceVo addDeviceVo) {
        return RespGenerator.returnOK(deviceService.addDevice(addDeviceVo));
    }


    @ApiOperation(value = "删除设备信息")
    @DeleteMapping("/deleteDevice")
    public BaseResponse<Boolean> deleteDevice(@RequestParam("deviceId") Integer deviceId) {
        return RespGenerator.returnOK(deviceService.deleteDevice(deviceId));
    }


}
